package com.viphuli.common;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.offroader.utils.LogUtils;
import com.viphuli.activity.MyToolBarActivity;
import com.viphuli.app.R;
import com.viphuli.fragment.AccountFeedbackFragment;
import com.viphuli.fragment.AccountLoginFragment;
import com.viphuli.fragment.AccountNurseJoinFragment;
import com.viphuli.fragment.AccountNurseJoinReadyFragment;
import com.viphuli.fragment.AccountShareFragment;
import com.viphuli.fragment.AccountTicketFragment;
import com.viphuli.fragment.HomeCompanyOrderFragment;
import com.viphuli.fragment.HomePrivateCustomFragment;
import com.viphuli.fragment.HomeServiceFragment;
import com.viphuli.fragment.HomeServiceInfoFragment;
import com.viphuli.fragment.MainFragment;
import com.viphuli.fragment.PurchaseOrderCommentFragment;
import com.viphuli.fragment.PurchaseOrderFillFragment;
import com.viphuli.fragment.PurchaseOrderInfoFragment;
import com.viphuli.fragment.PurchaseOrderPayFragment;
import com.viphuli.fragment.PurchaseOrderPayResultFailsFragment;
import com.viphuli.fragment.PurchaseOrderPayResultSuccessFragment;
import com.viphuli.fragment.SingleWebViewFragment;

public enum MyPageHelper {

	main(1, R.string.app_name, MainFragment.class), //主框架
	webView(2, R.string.str_single_webview_title, SingleWebViewFragment.class), //
	homeServiceHealth(3, R.string.str_main_content_service_item_health, HomeServiceFragment.class), //
	homeServiceNurse(4, R.string.str_main_content_service_item_nurse, HomeServiceFragment.class), //
	homeServiceInfo(5, R.string.str_main_content_service_item_info, HomeServiceInfoFragment.class), //
	purchaseOrderFill(6, R.string.title_main_home_service_item_info_order_fill, PurchaseOrderFillFragment.class), //
	purchaseOrderInfo(7, R.string.title_main_home_service_item_info_order_info, PurchaseOrderInfoFragment.class), //
	purchaseOrderPay(8, R.string.title_main_home_service_item_info_order_pay, PurchaseOrderPayFragment.class), //
	purchaseOrderComment(9, R.string.title_main_home_service_item_info_order_comment, PurchaseOrderCommentFragment.class), //
	purchasePaySuccess(10, R.string.str_order_pay_result_title, PurchaseOrderPayResultSuccessFragment.class), //
	purchasePayFails(11, R.string.str_order_pay_result_title, PurchaseOrderPayResultFailsFragment.class), //
	homePrivateCustom(12, R.string.str_main_content_service_private_custom, HomePrivateCustomFragment.class), //
	homeCompanyOrder(13, R.string.str_main_content_service_company_order, HomeCompanyOrderFragment.class), //
	accountLogin(14, R.string.str_account_login_title, AccountLoginFragment.class), //
	accountTicket(15, R.string.str_account_ticket_title, AccountTicketFragment.class), //
	accountFeedback(16, R.string.str_account_feedback_title, AccountFeedbackFragment.class), //
	accountNurseJoinReady(17, R.string.str_account_nurse_join_title, AccountNurseJoinReadyFragment.class), //
	accountNurseJoin(18, R.string.str_account_nurse_join_title, AccountNurseJoinFragment.class), //
	accountShare(19, R.string.str_account_share_title, AccountShareFragment.class), //
	;

	private int title;
	private Class<?> clz;
	private int value;

	private MyPageHelper(int value, int title, Class<?> clz) {
		this.value = value;
		this.title = title;
		this.clz = clz;
	}

	public void showMyPage(Activity ctx) {
		Bundle args = new Bundle();
		showMyPage(ctx, args);
	}

	public void showMyPage(Activity ctx, int resultCode) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		Bundle args = new Bundle();

		showMyPage(ctx, args, intent, resultCode);

	}

	public void showMyPage(Activity ctx, Bundle args, int resultCode) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);

		showMyPage(ctx, args, intent, resultCode);

	}

	public void showMyPage(Activity ctx, Bundle args) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);

		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPage(Activity ctx, Bundle args, String title) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, title);

		showMyPage(ctx, args, intent, 0);

	}

	public void showMyPageClearTop(Activity ctx, Bundle args) {

		Intent intent = new Intent(ctx, MyToolBarActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

		showMyPage(ctx, args, intent, 0);

	}

	private void showMyPage(Activity ctx, Bundle args, Intent intent, int resultCode) {

		if (args == null)
			args = new Bundle();

		//标题
		if (!args.containsKey(MyToolBarActivity.BUNDLE_KEY_TITLE))
			args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, ctx.getString(title));

		intent.putExtra(MyToolBarActivity.BUNDLE_KEY_ARGS, args);
		intent.putExtra(MyToolBarActivity.BUNDLE_KEY_PAGE, getValue());

		if (resultCode != 0) {
			ctx.startActivityForResult(intent, resultCode);
		} else {
			ctx.startActivity(intent);
		}

	}

	public void showMyWebViewPage(Activity ctx, String url, String title) {
		LogUtils.info("接口请求|打开网页" + title + "|" + url);
		Bundle args = new Bundle();
		args.putString(SingleWebViewFragment.BROWSER_URL, url);
		args.putString(MyToolBarActivity.BUNDLE_KEY_TITLE, title);
		showMyPage(ctx, args);
	}

	public int getTitle() {
		return title;
	}

	public void setTitle(int title) {
		this.title = title;
	}

	public Class<?> getClz() {
		return clz;
	}

	public void setClz(Class<?> clz) {
		this.clz = clz;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public static MyPageHelper getPageByValue(int val) {
		for (MyPageHelper p : values()) {
			if (p.getValue() == val)
				return p;
		}
		return null;
	}
}
